package com.crazy.jiakoulachang.controller;

import com.alibaba.excel.util.StringUtils;
import com.crazy.jiakoulachang.common.ApiRestResponse;
import com.crazy.jiakoulachang.exception.MallException;
import com.crazy.jiakoulachang.mapper.RoleMapper;
import com.crazy.jiakoulachang.pojo.Role;
import com.crazy.jiakoulachang.service.RoleService;
import io.swagger.annotations.Api;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * @author: lhy-卢辉宇
 * @date: 2023/6/24 20:55
 * @description:
 */
@RestController
@RequestMapping("/role")
@Api(tags = "登录角色控制类")
public class RoleController {

    @Resource
    private RoleService roleService;

    /**
     *    用户注册
     * @param userAccount
     * @param password
     * @param checkPassword
     * @return
     */

    @PostMapping("/register")
    public ApiRestResponse<Long> userRegister(@RequestParam String userAccount, @RequestParam String password,@RequestParam String checkPassword) throws MallException {
        long result = roleService.register(userAccount, password, checkPassword);
        return ApiRestResponse.success(result);
    }

    /**
     *    用户登录
     * @param userAccount
     * @param password
     * @param request
     * @return
     * @throws MallException
     */
    @PostMapping("/login")
    public ApiRestResponse<Role> userLogin(@RequestParam String userAccount, @RequestParam String password,HttpServletRequest request) throws MallException {
        Role role = roleService.login(userAccount, password, request);
        return ApiRestResponse.success(role);
    }

    @PostMapping("/login1")
    public String userLogin1(@RequestParam String userAccount, @RequestParam String password,HttpServletRequest request) throws MallException {
        Role role = roleService.login(userAccount, password, request);
        return "index";
    }


}
